package com.zxkj.commonpatrol.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.base.BaseViewModel;
import com.czy.basecommon.utils.base.StateLiveData;
import com.zxkj.commonpatrol.model.entity.DeciveEventEntity;
import com.zxkj.commonpatrol.model.response.DevEvtPatrolInfoResponse;
import com.zxkj.commonpatrol.model.response.DevEvtQuestPatrolHistoryResponse;
import com.zxkj.commonpatrol.repoisity.DeciveEventDetailRepoisity;

import java.util.ArrayList;
import java.util.List;

public class DeciveEventDetailViewModel extends BaseViewModel<DeciveEventDetailRepoisity> {
    public StateLiveData<List<DeciveEventEntity>> datas = new StateLiveData<>();
    public ObservableField<String>a=new ObservableField<>();
    public ObservableField<String>b=new ObservableField<>();
    public ObservableField<String>c=new ObservableField<>();

    public StateLiveData< List<DevEvtPatrolInfoResponse.DevEvtPatrolQuest>> Datas=new StateLiveData<>();
    public DeciveEventDetailViewModel(@NonNull Application application) {
        super(application);
    }

    public void getSelectData(int Type) {
        mRepository.getSelectProject(Type, new BaseRepository.MyBaseDataCallBack<List<DeciveEventEntity>>() {
            @Override
            public void onDataSuccessCallBack(List<DeciveEventEntity> deciveEventEntities) {
                datas.postSuccess(deciveEventEntities);
            }

            @Override
            public void onDataFailCallBack(List<DeciveEventEntity> deciveEventEntities, List<DeciveEventEntity> t1) {

            }
        });
    }

    public void getDevPatrolInfo(String RouteInspectNo, String PointNo, String DeviceNo,String QuestsNo, String Filter, int Categoryid,int Type) {
        mRepository.getDevPatrolInfo(RouteInspectNo, PointNo, DeviceNo,QuestsNo, Filter, Categoryid, Type,new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                DevEvtPatrolInfoResponse devEvtPatrolInfoResponse = (DevEvtPatrolInfoResponse) o;
                if (devEvtPatrolInfoResponse !=null){

                    a.set(devEvtPatrolInfoResponse.DevEvtQuestStatisInfo.Pending+"");
                    b.set(devEvtPatrolInfoResponse.DevEvtQuestStatisInfo.Completed+"");
                    c.set(devEvtPatrolInfoResponse.DevEvtQuestStatisInfo.All+"");

                    List<DevEvtPatrolInfoResponse.DevEvtPatrolQuest> devQuests = devEvtPatrolInfoResponse.getDevQuests();

                    if (devQuests == null ) {
                        devQuests=new ArrayList<>();
                    }
                    Datas.postSuccess(devQuests);
                }

            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {
                Datas.postFailure(404,(String)t1);
            }
        });
    }


}
